<template>
  <div>
    <div style="overflow: hidden">
      <div key="item.id" style="float: left">
        <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item>
            <a data="">个人中心>密码修改</a>
          </el-breadcrumb-item>
          <el-breadcrumb-item></el-breadcrumb-item>
        </el-breadcrumb>
      </div>
    </div>
    <!-- <div style="width: 70%; margin-top: 5%"> -->
    <el-form
      style="margin-top: 3%"
      :model="passData"
      status-icon
      label-width="150px"
      class="demo-ruleForm"
      ref="ruleForm"
    >
      <el-form-item label="修改密码">
        <el-input type="password" v-model="passData.pass"></el-input>
      </el-form-item>
      <el-form-item label="确认修改">
        <el-input type="password" v-model="passData.checkPass"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm">提交</el-button>
        <!-- <el-button @click="resetForm()">重置</el-button> -->
      </el-form-item>
    </el-form>
  </div>
</template>
 
<script>
export default {
  name: "countcontrol",
  data() {
    return {
      username: window.sessionStorage.getItem("token"),
      passData: {
        pass: "",
        checkPass: "",
      },
    };
  },
  methods: {
    submitForm() {
      // const that = this;
      // // 前端对表单数据进行校验
      // this.$refs[formName].validate((valid) => {
      //   if (!valid) {
      //     that.$message.error("密码格式不符合要求!!!");
      //     return false;
      //   }
      // 如果不想对密码数据格式校验，则直接执行以下代码就行
      if (this.passData.pass !== this.passData.checkPass) {
        this.$message.error("两次密码不一致!!!");
        return;
      }
      if (this.passData.pass.length < 6 || this.passData.pass.length > 15) {
        this.$message.error("密码长度应在6到15之间!!!");
        return;
      }
      var totalData = {
        username: this.username,
        password: this.passData.pass,
      };
      this.$http({
        url: "editPasswd",
        method: "post",
        data: totalData,
        headers: {
          "Content-Type": "application/json",
        },
      }).then((res) => {
        console.log(res);
        this.$router.push("/showinfos");
        this.$message.success("密码修改成功!!!");
        console.log("提交成功");
      });
    },
    resetForm() {
      this.$refs.formName.resetFields();
    },
  },
};
</script>
 
<style scoped>
</style>